import React from 'react'
import TheTable from '@/components/TheTable'
import ThePagination from '@/components/ThePagination'
import TheButton from '@/components/TheButton'
import {apiGetMhcResourcePage} from "@/request/callSetting/resourceSate";
//反馈信息
export default class FeedbackInfo extends React.Component {
    state = {
        columns: [
            {
                title: 'id',
                dataIndex: 'mhcResourceId',
                key: 'mhcResourceId'
            },
            {
                title: '资源位名称',
                dataIndex: 'resourceName',
                key: 'resourceName'
            },
            {
                title: '操作',
                fixed: 'right',
                render: (_, record) => {
                    return (
                        <div>
                            <TheButton haspermi={['call:resourceSate:edit']} onClick={() => this.onEdit(record)}>编辑</TheButton>
                            <TheButton haspermi={['call:resourceSate:view']} onClick={() => this.onView(record)}>查看</TheButton>
                        </div>
                    )
                }
            },
        ],
        dataSource: [],
        pageData: {
            pageNo: 1,
            pageSize: 10
        },
        total: 0
    }

    componentDidMount() {
        this.getData()
    }

    onEdit = (record) => {
        // 资源位管理端展示类型  TIPS/提示，说明  PUBLICIZE/资源位轮播图
        if (record.resourceShowType === 'PUBLICIZE') {
            this.props.history.push(`/settings/resourceSate/publicize/${record.mhcResourceId}/edit`)
        } else {
            this.props.history.push(`/settings/resourceSate/tips/${record.mhcResourceId}/edit`)
        }
    }
    onView = (record) => {
        // 资源位管理端展示类型  TIPS/提示，说明  PUBLICIZE/资源位轮播图
        if (record.resourceShowType === 'PUBLICIZE') {
            this.props.history.push(`/settings/resourceSate/publicize/${record.mhcResourceId}/view`)
        } else {
            this.props.history.push(`/settings/resourceSate/tips/${record.mhcResourceId}/view`)
        }
    }
    //获取数据
    getData = async () => {
        apiGetMhcResourcePage({...this.state.pageData}).then(res => {
            if (res.code === 0) {
                this.setState({
                    dataSource: res.data,
                    pageNo: res.pageNo,
                    pageSize: res.pageSize,
                    total: res.totalCount
                })
            }
        })
    }
    //切换分页
    pageChange = (pageNo, pageSize) => {
        this.setState({
            pageData: {pageNo, pageSize}
        }, () => {
            this.getData()
        })
    }

    render() {
        const {columns, dataSource, pageData: {pageNo, pageSize}, total} = this.state
        return (
            <div className='p-layout-box'>
                <div className="p-layout-content-pagination">
                    <TheTable columns={columns} dataSource={dataSource}/>
                    <ThePagination pageNo={pageNo} pageSize={pageSize} total={total} pageChange={this.pageChange}/>
                </div>
            </div>
        )
    }
}
